Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Collections.ObjectModel
Imports Microsoft.Health.PatientConnect

Public Class CheckStatusDlg

    Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
        btnUpdate.Text = "Processing..."
        btnUpdate.Enabled = False

        Dim pastDays As Integer = 0
        If radioPast7.Checked Then
            pastDays = 7
        Else
            pastDays = 30
        End If

        Try
            Dim connectionList As Collection(Of ValidatedPatientConnection) = DCHelper.Functions.GetValidatedConnectionsInPastDays(pastDays)
            For Each validatedConnection As ValidatedPatientConnection In connectionList
                'Update the XML store with the PersonId and RecordId of the user who has authorized our application
                'Also set the HasAuthorized flag to true for this participant
                XmlStore.UpdateParticipantToAuthorizedStatus(validatedConnection.ApplicationPatientId, _
                        validatedConnection.PersonId.ToString(), _
                        validatedConnection.RecordId.ToString())
            Next
            Dim confirmTemplate As String = "Found {0} authorizations and participant status updated"
            Dim confirmString As String = String.Format(confirmTemplate, connectionList.Count.ToString())
            MessageBox.Show(confirmString)
        Catch ex As Exception
            MessageBox.Show("Exception Occured:" + ex.Message)
        Finally
            btnUpdate.Text = "&Update participant status"
            btnUpdate.Enabled = True
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class